home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / rdslik1a / function.inc < prev    next >
Text File  |  1999-07-27  |  3KB  |  98 lines

  1. <%
  2.     sub DoDropDown (Name, SQLString,IDField, NameField, SelectedValue)
  3.         dim conn, rstemp
  4.         set Conn=server.createobject("adodb.connection")
  5.  
  6.         '******************************************************************************
  7.         'You can put the Connection parameters into application variables if you want!!
  8.         '******************************************************************************
  9.         '        conn.open Application("DSN"), Application("uid"), Application("pwd")
  10.         conn.open "TESTCOMBO", "Admin", ""
  11.  
  12.         %><select id = "<%=Name%>" name = "<%=Name%>"><%
  13.         
  14.         set rstemp=conn.execute(sqlString)
  15.         while not rstemp.eof%>
  16.             <option value="<%=rstemp(IDField)%>"<% 
  17.             if rstemp(IDField) = SelectedValue then
  18.                 %> selected=true <%
  19.             end if
  20.             %> > <%=rstemp(NameField)%><%
  21.             rstemp.movenext
  22.         wend
  23.         rstemp.close
  24.         set rstemp = nothing
  25.         conn.close
  26.         set conn = nothing
  27.     end sub
  28.  
  29.     Function CreateMaxIDExt(TableName1, FieldName1, FieldName2, FieldValue2)
  30.         Dim strSQL, Retries, CurrentTry, ConnTemp, RsTemp , CurrentMax, MustRetry
  31.         Retries = 50
  32.         CurrentTry = 0
  33.         MustRetry = True
  34.         set ConnTemp=server.createobject("adodb.connection")
  35.  
  36.         '******************************************************************************
  37.         'You can put the Connection parameters into application variables if you want!!
  38.         '******************************************************************************
  39.         '        ConnTemp.open Application("DSN"), Application("uid"), Application("pwd")
  40.         ConnTemp.open "TESTCOMBO", "Admin", ""
  41.  
  42.         On Error Resume Next
  43.         While MustRetry    
  44.             CurrentMax = GetMaxNum(TableName1, FieldName1) + 1
  45.             strSQL = "INSERT INTO " & TableName1 & " (" & FieldName1 & ", " & FieldName2 & ") VALUES (" & CurrentMax & ", "& FieldValue2 &")"
  46.             Set RsTemp = ConnTemp.Execute (strSQL)
  47.             if Err.Number <> 0 then
  48.                 CurrentTry = CurrentTry + 1
  49.                 if CurrentTry >= Retries then
  50.                     MustRetry = False
  51.                     CreateMaxIDExt = -1
  52.                     Response.Write("Couldn't add to table '"& TableName1 &"', field1 '"& FieldName1 &"', Field2 '"& FieldName2 &"' -> Value "& FieldValue2 &", Value '"& CurrentMax &"', Retried "& CurrentTry &" times.<BR>")
  53.                     Response.Write("Error Description:" & Err.Description & "<BR>Err Number:" & Err.Number & "<BR><BR>")
  54.                     response.write ("SQL : " & strSQL & "<BR>")
  55.                     Response.End
  56.                     Exit Function
  57.                 end if 
  58.                 Err.Clear
  59.             else
  60.                 MustRetry = False
  61.             end if
  62.         Wend
  63.         CreateMaxIDExt = CurrentMax
  64.         Exit Function
  65.     End Function
  66.  
  67.  
  68.     Function GetMaxNum(TableName, FieldName)
  69.         dim conntemp2, rstemp2, sqltemp2
  70.         set conntemp2=server.createobject("adodb.connection")
  71.  
  72.  
  73.         '******************************************************************************
  74.         'You can put the Connection parameters into application variables if you want!!
  75.         '******************************************************************************
  76.         '        connTemp2.open Application("DSN"), Application("uid"), Application("pwd")
  77.         ConnTemp2.open "TESTCOMBO", "Admin", ""
  78.  
  79.         sqltemp2= "SELECT Max("& FieldName &") FROM "& TableName 
  80.         set rstemp2=conntemp2.execute(SQLTemp2)
  81.         if not rstemp2.eof then
  82.             GetMaxNum = iif(isnull(rstemp2(0)),0,rstemp2(0))
  83.         else
  84.             GetMaxNum = 0
  85.         end if
  86.         set rstemp2 = nothing
  87.         set conntemp2 = nothing
  88.     End Function
  89.  
  90.     Function iif(CheckThis, ValTrue, ValFalse)
  91.         if CheckThis then
  92.             iif=ValTrue
  93.         else
  94.             iif=ValFalse
  95.         end if
  96.     End Function
  97.  
  98. %>